package com.ctbri.manage.process.utils;

import com.ctbri.manage.process.model.GeneratorConfig;
import org.springframework.jdbc.core.JdbcTemplate;
import com.alibaba.druid.pool.DruidDataSource;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author qs
 */
public class DbOperationUtils {
    public  static JdbcTemplate getJdbcTemplate() {

        // com.alibaba.druid.pool.DruidDataSource
        DruidDataSource dataSource = new DruidDataSource();
        Properties properties = new Properties();
     /*   try {
            InputStream path = DbOperationUtils.class.getResourceAsStream("/jdbc.properties");
            properties.load(new InputStreamReader(path, "UTF-8"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/
        // 设置数据源属性参数
        dataSource.setDriverClassName(properties.get("jdbc.driverName").toString());
        dataSource.setUrl(properties.get("jdbc.jdbcUrl").toString());
        dataSource.setUsername(properties.get("jdbc.username").toString());
        dataSource.setPassword(properties.get("jdbc.password").toString());

        // 获取spring的JdbcTemplate
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        // 设置数据源
        jdbcTemplate.setDataSource(dataSource);

        return jdbcTemplate;
    }
}
